#__Author__  = white
#-*-coding=utf_8-*-


def show():
    with open("file",'r') as f :
        for line in f:
            print(line)
            # line = eval(line)
            # for i in line:
            #   print(i)
    return 0


def add(arg):
    arg = str(arg)
    with open("file",'a') as f:
        f.write("\n")
        f.write(arg)

def find_str(arg):
    arg = arg
    flag = False
    with open("file",'r') as f:
        for line in f:
            if arg in line:
                flag = True
    return flag

def delete(arg):
    arg = arg
    with open("file_bak",'w') as f_bak,\
         open("file",'r') as f:
             for line in f:
                if arg in line:
                     continue
                f_bak.write(line)
    return 0

arg = {
        'bakend':'www.yyy.org',
        'record':{
            'server':'104.1.7.9',
            'weight': 24,
            'maxconm': 34
        }

    }

# show()
# print(find_str("record"))
# delete("www.yyy.org")


while 1:
    print("列表展示：\nshow\nsearch\nadd\ndelete\n")
    print("请输入你想操作的内容:\n")
    shuru = input()
    if shuru == "show":
        show()
        #print("列表展示：\nshow\nsearch\nadd\ndelete\n")
    elif shuru == "search":
        print("请输入你要查找的内容\n")
        search = input()
        res_out=find_str(search)
        if res_out == True:
            print("找到了\n")
        else:
            print("未找到\n")
        #print("列表展示：\nshow\nsearch\nadd\ndelete\n")
    elif shuru == "add":
        print("请输入你要增加的内容\n")
        add_str = input()
        add(add_str)
        print("添加成功\n")
        #print("列表展示：\nshow\nsearch\nadd\ndelete\n")
    elif shuru == "delete":
        print("请输入你要删除的内容\n")
        del_str = input()
        delete(del_str)
        print("删除成功\n")
        #print("列表展示：\nshow\nsearch\nadd\ndelete\n")
    else:
        print("退出")
        exit()
